<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">

    <link rel="shortcut icon" href="./favicon.ico">
    <link rel="stylesheet" href="/assets/font/css/material-design-iconic-font.css">
    <link rel="stylesheet" href="/assets/animate/animate.css">
    <link rel="stylesheet" href="/assets/toastr/toastr.min.css">
    <link rel="stylesheet" href="/assets/app/app.css">
    <link rel="stylesheet" href="/assets/login/style.css">
</head>

<body data-ma-theme="green" style="overflow: hidden">
<div class="login" id="login">
    <!-- 登录 -->
    <div class="login__block active" id="l-login">
        <div class="login__block__header">
            <i class="zmdi zmdi-account-circle"></i>
            你好！请登录CIIS系统管理平台
        </div>
        <div class="login__block__body">
            <form id="login_form" onsubmit="return false" action="/login/doLogin?returnUrl=#(returnUrl)" method="post">
                #(token)
                #if(devMode)
                <div class="form-group form-group--float form-group--centered">
                    <input type="text" name="userName" value="ce" class="form-control">
                    <label>用户名</label>
                    <i class="form-group__bar"></i>
                </div>
                <div class="form-group form-group--float form-group--centered">
                    <input type="password" name="password" value="Aa111111" class="form-control" >
                    <label>密码</label>
                    <i class="form-group__bar"></i>
                </div>
                #else
                <div class="form-group form-group--float form-group--centered">
                    <input type="text" name="userName" class="form-control">
                    <label>用户名</label>
                    <i class="form-group__bar"></i>
                </div>
                <div class="form-group form-group--float form-group--centered">
                    <input type="password" name="password" class="form-control" >
                    <label>密码</label>
                    <i class="form-group__bar"></i>
                </div>
                #end
                <div class="form-group">
                    <label class="custom-control custom-checkbox">
                        <input type="checkbox" class="custom-control-input" name="keepLogin" value='1' checked>
                        <span class="custom-control-indicator"></span>
                        <span class="custom-control-description">保持登录<span style="color: red">(请勿在公用电脑上使用)</span></span>
                    </label>
                </div>

                <button type="button" onclick="loginBtn()" class="btn btn--icon login__block__btn"><i
                        class="zmdi zmdi-long-arrow-right"></i>
                </button>
            </form>
        </div>
    </div>
</div>
<!-- Javascript -->
<script src="/assets/jquery/jquery.min.js"></script>
<script src="/assets/bootstrap/bootstrap.js"></script>
<script src="/assets/jquery_form/jquery.form.js"></script>
<script src="/assets/app/app.min.js"></script>
<script src='/assets/toastr/toastr.min.js'></script>
<script>
    function showMsg(type, msg) {
        toastr.options = {
            "closeButton": true, // 是否显示关闭按钮
            "debug": false, // 是否使用debug模式
            "progressBar": true,// 显示进度条
            "positionClass": "toast-bottom-right",// 弹出窗的位置 右下
            "showDuration": "300",// 显示的动画时间
            "hideDuration": "1000",// 消失的动画时间
            "timeOut": "5000", // 展现时间
            "extendedTimeOut": "1000",// 加长展示时间
            "showEasing": "swing",// 显示时的动画缓冲方式
            "hideEasing": "linear",// 消失时的动画缓冲方式
            "showMethod": "fadeIn",// 显示时的动画方式
            "hideMethod": "fadeOut" // 消失时的动画方式
        };

        if (type == "success" || type == 0) {// 成功
            toastr.success(msg, "成功通知");
        } else if (type == "info" || type == 1) {// 提示
            toastr.info(msg, "提示通知");
        } else if (type == "warning" || type == 2) {// 警告
            toastr.warning(msg, "警告通知");
        } else if (type == "error" || type == 3) {// 错误
            toastr.error(msg, "错误通知");
        } else if (type == "clear" || type == 4) {// 清除
            toastr.clear();
        }
    }

    $(document).ready(function () {
        $("#submit_btn").bind("click", sendRetrievePasswordEmail);
    })

    /**
     * 登陆
     */
    //为keyListener方法注册按键事件
    document.onkeydown = keyListener;

    function keyListener(e) {
        // 当按下回车键，执行我们的代码
        if (e.keyCode == 13) {
            loginBtn();
        }
    }

    function loginBtn() {
        ajaxSubmit("/login/doLogin?returnUrl=#(returnUrl)", $('#login_form').serialize(), "/admin");
    }
    function ajaxSubmit(postUrl, data, sucUrl) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: postUrl,
            data: data,
            success: function (ret) {
                if (ret.state == 'ok') {
                    location.href = sucUrl;
                    return;
                } else {
                    showMsg(2, ret.msg);
                    return;
                }
            },
            error: function () {
                alert("异常！");
            }
        });
    }
    /**
     * 注册
     */

    function regBtn(t) {
        $(t).attr("disabled", "disabled");
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/reg/save",
            data: $('#reg_form').serialize(),
            success: function (ret) {
                if (ret.state == 'ok') {
                    showMsg(0, ret.msg);
                    $("#login").hide();
                    $("#regOkPanel,#regOkPanel > div").show();
                    $("#retriveOkPanel").hide();
                    $("#regEmail").text(ret.regEmail);
                } else {
                    showMsg(2, ret.msg);
                    $(t).removeAttr("disabled");
                }
            },
            error: function () {
                alert("异常！");
            }
        });
    }


    function activaBtn() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/reg/reSendActivateEmail",
            data: $('#activa_form').serialize(),
            success: function (ret) {
                if (ret.state == 'ok') {
                    showMsg(0, ret.msg);
                    $("#login").hide();
                    $("#regOkPanel,#regOkPanel > div").show();
                    $("#retriveOkPanel").hide();
                    $("#regEmail").text(ret.regEmail);
                    return;
                } else {
                    showMsg(2, ret.msg);
                    return;
                }
            },
            error: function () {
                alert("异常！");
            }
        });
    }


    function sendRetrievePasswordEmail() {
        $.ajax("/login/sendRetrievePasswordEmail", {
            type: "POST"
            , cache: false
            , dataType: "json"
            , data: {email: $("#email").val()}
            , beforeSend: function () {
                $("#submit_btn").attr("disabled", true);
            }
            , success: function (ret) {
                if (ret.state == 'ok') {
                    showMsg(0, ret.msg);
                    $("#login").hide();
                    $("#regOkPanel,#regOkPanel > div").hide();
                    $("#regEmail").text(ret.regEmail);
                    $("#retriveOkPanel,#retriveOkPanel >div").show();
                } else {
                    showMsg(3, ret.msg);
                    $("#submit_btn").attr("disabled", false);
                }
            }
        });
    }
</script>

</body>
</html>